
#include ".\tex_mgr.h"
#include "pageInfoGetter.hpp"
#include "ilttexinterface.h"
#include "..\clientinterfaces.h"
tex_mgr::tex_mgr(void):
m_tex_file("Screen/tex.txt"),
m_page_name("tex")
{
	
	//Utility::page_info_getter::Instance().add_page("./rez/"+m_tex_file,m_page_name);
	m_size=Utility::page_info_getter::Instance().get(m_page_name,"info","size",m_size);
	for (int i=0;i<m_size;++i)
	{
		 static int tempid;
		 static std::string tempstr;
		char tempgroup[10];
		sprintf(tempgroup,"tex%d",i);
		tempid=Utility::page_info_getter::Instance().get(m_page_name,tempgroup,"id",tempid);
		tempstr=Utility::page_info_getter::Instance().get(m_page_name,tempgroup,"name",tempstr);
		m_texs.insert(std::make_pair(tempstr,tempid));
		LTRESULT result=0;
		result=g_pLTCTexInterface->CreateTextureFromName(temphtex,("Screen/textures/"+tempstr+".dtx").c_str());
	
		m_texs_value.insert(std::make_pair(tempid,temphtex));
		

	}
	
}

tex_mgr::~tex_mgr(void)
{
	for (m_texs_value_it=m_texs_value.begin();m_texs_value_it!=m_texs_value.end();++m_texs_value_it	)
	{
		g_pLTCTexInterface->ReleaseTextureHandle((*m_texs_value_it).second);
	}
	m_texs.clear();
}
tex_mgr& tex_mgr::single()
{
	static tex_mgr _single;
	return _single;
}

int tex_mgr::get_tex_nums()
{
	return m_texs.size();
}



HTEXTURE tex_mgr::get_tex( int id )
{
	return m_texs_value[id];
}

HTEXTURE tex_mgr::get_tex( std::string name )
{
	int id=m_texs[name];
	return m_texs_value[id];

}